inspector: Add a magnifier
authorMatthias Clasen <mclasen@redhat.com>
Sun, 21 Dec 2014 00:24:08 +0000 (19:24 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 21 Dec 2014 00:24:08 +0000 (19:24 -0500)
Add a magnifier that shows the selected widget up to 5 times
enlarged.

gtk/inspector/Makefile.inc
gtk/inspector/init.c
gtk/inspector/magnifier.c [new file with mode: 0644]
gtk/inspector/magnifier.h [new file with mode: 0644]
gtk/inspector/magnifier.ui.h [new file with mode: 0644]
gtk/inspector/window.c
gtk/inspector/window.h
gtk/inspector/window.ui
gtk/inspector/window.ui.h
po/POTFILES.in

index 5c966df04b1f1cfd8ea248db37bf9d1c51b30075..464e8094971066dca72368a3f575374e19971d53 100644 (file)
@@ -10,6 +10,7 @@ inspector_c_sources =                         \
        inspector/graphdata.c           \
        inspector/init.c                \
        inspector/inspect-button.c      \
+       inspector/magnifier.c           \
        inspector/menu.c                \
        inspector/misc-info.c           \
        inspector/object-hierarchy.c    \
@@ -37,6 +38,7 @@ inspector_h_sources =                         \
        inspector/gestures.h            \
        inspector/graphdata.h           \
        inspector/init.h                \
+       inspector/magnifier.h           \
        inspector/menu.h                \
        inspector/misc-info.h           \
        inspector/object-hierarchy.h    \
@@ -59,6 +61,7 @@ inspector_templates =                 \
        inspector/css-editor.ui         \
        inspector/data-list.ui          \
        inspector/general.ui            \
+       inspector/magnifier.ui          \
        inspector/menu.ui               \
        inspector/misc-info.ui          \
        inspector/object-hierarchy.ui   \
index c930948a1197b28bb8a6921718919b956cf0e685..14acd8e66e536055085c2f18fae4101e7c0e3724 100644 (file)
@@ -32,6 +32,7 @@
 #include "general.h"
 #include "gestures.h"
 #include "graphdata.h"
+#include "magnifier.h"
 #include "menu.h"
 #include "misc-info.h"
 #include "object-hierarchy.h"
@@ -46,6 +47,8 @@
 #include "visual.h"
 #include "window.h"
 
+#include "gtkmagnifierprivate.h"
+
 #include "gtkmodulesprivate.h"
 
 void
@@ -61,6 +64,8 @@ gtk_inspector_init (void)
   g_type_ensure (GTK_TYPE_INSPECTOR_DATA_LIST);
   g_type_ensure (GTK_TYPE_INSPECTOR_GENERAL);
   g_type_ensure (GTK_TYPE_INSPECTOR_GESTURES);
+  g_type_ensure (GTK_TYPE_MAGNIFIER);
+  g_type_ensure (GTK_TYPE_INSPECTOR_MAGNIFIER);
   g_type_ensure (GTK_TYPE_INSPECTOR_MENU);
   g_type_ensure (GTK_TYPE_INSPECTOR_MISC_INFO);
   g_type_ensure (GTK_TYPE_INSPECTOR_OBJECT_HIERARCHY);
diff --git a/gtk/inspector/magnifier.c b/gtk/inspector/magnifier.c
new file mode 100644 (file)
index 0000000..c7b4a5b
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#include "magnifier.h"
+
+#include "gtkmagnifierprivate.h"
+
+#include "gtklabel.h"
+
+
+struct _GtkInspectorMagnifierPrivate
+{
+  GtkWidget *object;
+  GtkWidget *magnifier;
+  GtkWidget *object_title;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorMagnifier, gtk_inspector_magnifier, GTK_TYPE_BOX)
+
+static void
+gtk_inspector_magnifier_init (GtkInspectorMagnifier *sl)
+{
+  sl->priv = gtk_inspector_magnifier_get_instance_private (sl);
+  gtk_widget_init_template (GTK_WIDGET (sl));
+}
+
+void
+gtk_inspector_magnifier_set_object (GtkInspectorMagnifier *sl,
+                                    GObject              *object)
+{
+  const gchar *title;
+
+  sl->priv->object = NULL;
+
+  if (!GTK_IS_WIDGET (object))
+    {
+      gtk_widget_hide (GTK_WIDGET (sl));
+      _gtk_magnifier_set_inspected (GTK_MAGNIFIER (sl->priv->magnifier), NULL);
+      return;
+    }
+
+  title = (const gchar *)g_object_get_data (object, "gtk-inspector-object-title");
+  gtk_label_set_label (GTK_LABEL (sl->priv->object_title), title);
+
+  gtk_widget_show (GTK_WIDGET (sl));
+
+  sl->priv->object = GTK_WIDGET (object);
+
+  _gtk_magnifier_set_inspected (GTK_MAGNIFIER (sl->priv->magnifier), GTK_WIDGET (object));
+  _gtk_magnifier_set_coords (GTK_MAGNIFIER (sl->priv->magnifier), 0, 0);
+}
+
+static void
+gtk_inspector_magnifier_class_init (GtkInspectorMagnifierClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/magnifier.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMagnifier, magnifier);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMagnifier, object_title);
+}
+
+// vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/magnifier.h b/gtk/inspector/magnifier.h
new file mode 100644 (file)
index 0000000..2dcac6f
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GTK_INSPECTOR_MAGNIFIER_H_
+#define _GTK_INSPECTOR_MAGNIFIER_H_
+
+#include <gtk/gtkbox.h>
+
+#define GTK_TYPE_INSPECTOR_MAGNIFIER            (gtk_inspector_magnifier_get_type())
+#define GTK_INSPECTOR_MAGNIFIER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_INSPECTOR_MAGNIFIER, GtkInspectorMagnifier))
+#define GTK_INSPECTOR_MAGNIFIER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_INSPECTOR_MAGNIFIER, GtkInspectorMagnifierClass))
+#define GTK_INSPECTOR_IS_MAGNIFIER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_INSPECTOR_MAGNIFIER))
+#define GTK_INSPECTOR_IS_MAGNIFIER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_INSPECTOR_MAGNIFIER))
+#define GTK_INSPECTOR_MAGNIFIER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_INSPECTOR_MAGNIFIER, GtkInspectorMagnifierClass))
+
+
+typedef struct _GtkInspectorMagnifierPrivate GtkInspectorMagnifierPrivate;
+
+typedef struct _GtkInspectorMagnifier
+{
+  GtkBox parent;
+  GtkInspectorMagnifierPrivate *priv;
+} GtkInspectorMagnifier;
+
+typedef struct _GtkInspectorMagnifierClass
+{
+  GtkBoxClass parent;
+} GtkInspectorMagnifierClass;
+
+G_BEGIN_DECLS
+
+GType      gtk_inspector_magnifier_get_type   (void);
+void       gtk_inspector_magnifier_set_object (GtkInspectorMagnifier *sl,
+                                               GObject               *object);
+
+G_END_DECLS
+
+#endif // _GTK_INSPECTOR_MAGNIFIER_H_
+
+// vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/magnifier.ui.h b/gtk/inspector/magnifier.ui.h
new file mode 100644 (file)
index 0000000..e69de29
index 1e7223b89e0998c072fefa1e18d9e5eb787da6fa..3846ecdcdd3df0ed9843ce995d5cba580c8f0cd7 100644 (file)
@@ -42,6 +42,7 @@
 #include "menu.h"
 #include "misc-info.h"
 #include "gestures.h"
+#include "magnifier.h"
 
 #include "gtklabel.h"
 #include "gtkbutton.h"
@@ -75,6 +76,7 @@ set_selected_object (GtkInspectorWindow *iw,
   gtk_inspector_actions_set_object (GTK_INSPECTOR_ACTIONS (iw->actions), selected);
   gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
   gtk_inspector_gestures_set_object (GTK_INSPECTOR_GESTURES (iw->gestures), selected);
+  gtk_inspector_magnifier_set_object (GTK_INSPECTOR_MAGNIFIER (iw->magnifier), selected);
 
   for (l = iw->extra_pages; l != NULL; l = l->next)
     g_object_set (l->data, "object", selected, NULL);
@@ -234,6 +236,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, misc_info);
   gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, gestures);
+  gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, magnifier);
 
   gtk_widget_class_bind_template_callback (widget_class, gtk_inspector_on_inspect);
   gtk_widget_class_bind_template_callback (widget_class, on_object_activated);
index 8560e0c710adeed8d22c154dbb11486e92376a8c..07a469d8eb8f7b29d5a5b56c16413afe586878de 100644 (file)
@@ -64,6 +64,7 @@ typedef struct
   GtkWidget *menu;
   GtkWidget *misc_info;
   GtkWidget *gestures;
+  GtkWidget *magnifier;
 
   GtkWidget *invisible;
   GtkWidget *selected_widget;
@@ -99,7 +100,6 @@ void       gtk_inspector_on_inspect         (GtkWidget          *widget,
 
 void       gtk_inspector_window_select_widget_under_pointer (GtkInspectorWindow *iw);
 
-                                            
 
 G_END_DECLS
 
index 366d1791a5600e688d1f12dfb9b213766eb77d25..6046618ceb0af10371f7fc7a54d437f23466cc70 100644 (file)
                             <property name="title" translatable="yes">Gestures</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkInspectorMagnifier" id="magnifier">
+                          </object>
+                          <packing>
+                            <property name="name">magnifier</property>
+                            <property name="title" translatable="yes">Magnifier</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                   </object>
index 498011ce272eec48344d9da29c78196619ec3849..05c6b2126c46c949c4711702ba90990cb08f5a88 100644 (file)
@@ -18,6 +18,7 @@ N_("Data");
 N_("Actions");
 N_("Menu");
 N_("Gestures");
+N_("Magnifier");
 N_("Objects");
 N_("Statistics");
 N_("Resources");
index 2bac9c0f692c1f96dd8ae11b46945d64fc3da658..62aef2320482205cb15f7bbf42f89476ac9a1ffc 100644 (file)
@@ -292,6 +292,7 @@ gtk/inspector/general.ui.h
 gtk/inspector/gestures.c
 gtk/inspector/inspect-button.c
 gtk/inspector/menu.c
+gtk/inspector/magnifier.ui.h
 gtk/inspector/menu.ui.h
 gtk/inspector/misc-info.c
 gtk/inspector/misc-info.ui.h